package com.example.springboot.controller;

import com.example.springboot.pojo.Student;
import jakarta.websocket.server.PathParam;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Array;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;

@RestController
public class HelloController {
    private final String string = "/complexParam";

    @RequestMapping("/hello")
    public String sayHeelo() {
        System.out.println("hello");
        return "hello word";
    }


    //        接受前端数据
    @RequestMapping("/simpleParam")
    public String simpleParam(String name) {
        System.out.println(name);
        return name;

    }

    @GetMapping("/simpleParam0")
    public String simpleParam0(String name) {
        System.out.println(name);
        return name;

    }


    @RequestMapping("/simpleParam1")
    public String simpleParam1(Student student) {
        System.out.println(student);
        return student.toString();

    }

    @RequestMapping(string)
    public String complexParam(Student student) {
        System.out.println(student);
        return student.toString();
    }

    @RequestMapping("/arrayParam")
    public String arrayParam(String[] hobby) {
        System.out.println(Arrays.toString(hobby));
        return Arrays.toString(hobby);
    }

    @RequestMapping("/arrayParam1")
    public String arrayParam1(@RequestParam List<String> hobby) {
        System.out.println(hobby);
        return hobby.toString();
    }

    @RequestMapping("/timeParam")
    public String timeParam(@DateTimeFormat(pattern = "yyyy-MM-DD HH:mm:ss") LocalDateTime time) {
        System.out.println(time);
        return time.toString();
    }

    //    json格式 post body raw Json
    @RequestMapping("/jsonParam")
    public String jsonParam(@RequestBody Student student) {
        System.out.println(student);
        return student.toString();
    }
//    路径参数
    /*
    restful 风格开发
    get方式 http://localhost/pathParam/1 查询1
    put方式 http://localhost/pathParam/1 修改1

    后端接受
    @DeleteMapping
     */
    @RequestMapping("/pathParam/{id}")
    public String pahtParam(@PathVariable Integer id) {
        System.out.println(id);
        return id+"";
    }



}
